<?php

class GradeRequest extends CActiveRecord {

    const ACTION_COMPILE = 0;
    const ACTION_GRADE = 1;
    const ACTION_EXECUTE = 2;
    
    const STATUS_PENDING = 0;
    const STATUS_GRADING = 1;
    const STATUS_GRADED = 2;
    
    const MODE_SYNCHRONOUS = 0;
    const MODE_ASYNCHRONOUS = 1;

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function tableName() {
        return '{{grade_requests}}';
    }
    
    public function rules() {
        return array(
            array('evaluationset_id, submitter_id, mode', 'required'),
            array('source_file' , 'safe'),
            array('request_id' , 'safe')
        );
    }
    
    protected function beforeSave() {
        if ($this->isNewRecord) {
            $this->receive_time = new CDbExpression("NOW()");
            $this->status = self::STATUS_PENDING;
        }
        return parent::beforeSave();
    }

    public function relations() {
        return array(
            'evaluationset' => array(self::BELONGS_TO, 'EvaluationSet', 'evaluationset_id'),
            'request' => array(self::BELONGS_TO, 'ServiceRequest', 'request_id'),
        );
    }

}

?>
